package 字符串与String的相互转换;

/**
 * @author feng
 * @Date 2022/1/2 9:19
 * 两个字符串中最大相同的子串。
 * "qwerabcdtyuiop"
 * "xcabcdvbn"
 */
public class Test3 {
    public static void main(String[] args) {
        String s1 = "qwerabcdtyuiop";
        String s2 = "xcabcdvbn";
        String s = getMaxSubSting(s1, s2);
        System.out.println(s);
    }

    private static String getMaxSubSting(String s1, String s2) {
        String max = null;
        String min = null;
        if (s1.length() >= s2.length()) {
            max = s1;
            min = s2;
        } else {
            max = s2;
            min = s1;
        }

        for (int i = 0; i < min.length(); i++) {
            for (int a = 0, b = min.length() - i; b != min.length() + 1; a++,b++) {
                String sub = min.substring(a, b);
                if (max.contains(sub))
                    return sub;
            }
        }

        return null;
    }
}
